package com.example;

import com.example.domain.Car;
import com.example.domain.TestBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * <p> BeanFacotory 测试 </p>
 *
 * @author Chris
 * @since 2022/9/13 15:25
 */
public class BeanFactoryTest {

    public static void main(String[] args) {
        // 基本容器使用
        System.out.println("---------基本容器使用---------------------");
        final BeanFactory bf = new XmlBeanFactory(new ClassPathResource("beanFactoryTest.xml"));
        final Car car = (Car) bf.getBean("car");
        System.out.println(car);
        final Object bean = bf.getBean("&car");
        System.out.println(bean);
        System.out.println("---------基本容器使用---------------------");

        // 高级容器使用
        System.out.println("---------高级容器使用---------------------");
        final ApplicationContext context = new ClassPathXmlApplicationContext("beanFactoryTest.xml");
        final TestBean testBean = (TestBean) context.getBean("testBean");
        testBean.test();
        System.out.println("---------高级容器使用---------------------");

    }

}